﻿/// Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.ServiceModel.Activation;
using System.Linq;
using System.Net;
using Microsoft.ServiceModel.Web;
using System.Xml.Linq;

// The following line sets the default namespace for DataContract serialized typed to be ""
[assembly: ContractNamespace("", ClrNamespace = "AccountDispatch")]

namespace AccountDispatch
{

    [ServiceBehavior(IncludeExceptionDetailInFaults = true, InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceContract]
    public partial class Service
    {

        [WebGet(UriTemplate = "GetAccountJson?UserId={UserId}", ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        Account[] GetAccountJson(string UserId)
        {
            AccountFetcher myFetcher = new AccountFetcher();
            return myFetcher.GetAccounts(UserId);
            //return "This is jsonData: " + s;
        }

        [WebGet(UriTemplate = "GetAccountPOX?UserId={UserId}")]
        [OperationContract]
        Account[] GetAccountPOX(string UserId)
        {
            // call the database and return values.
            AccountFetcher myFetcher = new AccountFetcher();
            return myFetcher.GetAccounts(UserId);
        }

        [WebGet(UriTemplate = "AddAccountPOX?UserId={UserId}&name={name}&number={number}")]
        [OperationContract]
        Message AddAccountPOX(string UserId, string name, string number)
        {
            // call the database and return values.
            AccountFetcher myFetcher = new AccountFetcher();
            return myFetcher.AddAccount(UserId, name, number);
        }

        [WebGet(UriTemplate = "AddAccountJson?UserId={UserId}&name={name}&number={number}", ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        Message AddAccountJson(string UserId, string name, string number)
        {
            // call the database and return values.
            AccountFetcher myFetcher = new AccountFetcher();
            return myFetcher.AddAccount(UserId, name, number);
        }

        [WebGet(UriTemplate = "DeleteAccountPOX?UniqueId={UniqueId}")]
        [OperationContract]
        Message DeleteAccountPOX(string UniqueId)
        {
            // call the database and return values.
            AccountFetcher myFetcher = new AccountFetcher();
            return myFetcher.DeleteAccount(UniqueId);
        }

        [WebGet(UriTemplate = "DeleteAccountJson?UniqueId={UniqueId}", ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        Message DeleteAccountJson(string UniqueId)
        {
            // call the database and return values.
            AccountFetcher myFetcher = new AccountFetcher();
            return myFetcher.DeleteAccount(UniqueId);
        }

        [WebGet(UriTemplate = "UpdateAccountPOX?UserId={UserId}&name={name}&number={number}")]
        [OperationContract]
        Message UpdateAccountPOX(string UserId, string name, string number)
        {
            // call the database and return values.
            AccountFetcher myFetcher = new AccountFetcher();
            return myFetcher.UpdateAccount(UserId, name, number);
        }

        [WebGet(UriTemplate = "UpdateAccountJson?UserId={UserId}&name={name}&number={number}", ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        Message UpdateAccountJson(string UserId, string name, string number)
        {
            // call the database and return values.
            AccountFetcher myFetcher = new AccountFetcher();
            return myFetcher.UpdateAccount(UserId, name, number);
        }


    }

}